package demo.standard;

import java.util.HashMap;
import java.util.Map;

public class FlyWeightFactory {

    private static Map<String, IFlyWeight> flyWeights = new HashMap<>();

    public static IFlyWeight getFlyWeight(String key) {
        if (flyWeights.containsKey(key)) {
            System.out.println("从内存中获得共享对象,内部状态:" + key);
            return flyWeights.get(key);
        }

        ConcreteFlyWeight flyWeight = new ConcreteFlyWeight(key);
        flyWeights.put(key, flyWeight);
        return flyWeight;
    }
}
